﻿using System;
using System.Collections.Generic;
using System.Text;
using Model;
using System.Linq;
using System.Data;
using IHotelDal;
using HotelDal;
using Microsoft.EntityFrameworkCore;

namespace HotelDal
{
    /// <summary>
    /// 曹士恒
    /// 功能模块:娱乐管理
    /// </summary>
    public class RecreationDAL : IRecreationsDALs
    {
        MyDbcontext db = new MyDbcontext();
        /// <summary>
        /// 显示娱乐项目
        /// </summary>
        /// <returns></returns>
        public List<Recreation> RecreationShow()
        {
            List<Recreation> list = (from s in db.Recreation
                                     join t in db.Amusement on s.Rname equals t.Aid
                                     select new Recreation
                                     {
                                         Rid = s.Rid,
                                         Aname = t.Aname,
                                         RkaiTime = s.RkaiTime,
                                         Rname = s.Rname,
                                         RjieTime = s.RjieTime,
                                         Rprincipal = s.Rprincipal,
                                         Aprice = t.Aprice,
                                         Rstate = s.Rstate,
                                         Acomment = t.Acomment,
                                     }
                                   ).ToList();
            return list;
        }
        /// <summary>
        /// 显示项目
        /// </summary>
        /// <returns></returns>
        public List<Amusement> AmusementShow()
        {
            List<Amusement> list = (from s in db.Amusement
                                    select new Amusement
                                    {
                                        Acomment = s.Acomment,
                                        Aid = s.Aid,
                                        Aname = s.Aname,
                                        Aprice = s.Aprice
                                    }
                                   ).ToList();
            return list;
        }
        /// <summary>
        /// 删除项目
        /// </summary>
        /// <param name="id"></param> 
        /// <returns></returns>
        public int Del(int id)
        {
            var sid = db.recreation.Find(id);
            db.recreation.Remove(sid);
            return db.SaveChanges();

        }
        /// <summary>
        /// 删除娱乐项目
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public int Delam(int id)
        {
            var sid = db.Amusement.Find(id);
            db.Amusement.Remove(sid);
            return db.SaveChanges();

        }
        /// <summary>
        /// 添加项目
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int AddAmusement(Amusement m)
        {
            db.Amusement.Add(m);
            return db.SaveChanges();

        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="m"></param>
        /// <returns></returns>
        public int AddRecren(Recreationlist m)
        {
            db.recreation.Add(m);
            return db.SaveChanges();
        
        }
        /// <summary>
        /// 根据id获取数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Recreationlist Find(int id)
        {
            return db.recreation.Find(id);

        }
        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="m"></param> 
        /// <returns></returns>
        public int UptRecreation(Recreationlist m)
        {
            var s = db.recreation.Where(t => t.Rid.Equals(m.Rid)).FirstOrDefault();          
            var name = db.recreation.Attach(m);
            return db.SaveChanges();
        }
    }
}
